package com.zjlp.seproject.mapper;

import com.zjlp.seproject.pojo.*;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
public interface SubjectMapper {

    List<Subject> selectAll();

    int deleteByPrimaryKey(Integer id);

    int insert(Subject record);

    //详情页
    @Select("select * from subject where id = #{id} and adopt = 1")
    Subject selectByPrimaryKey(Integer id);

    int updateByPrimaryKey(Subject record);

    //首页信息获取
    @Select("select id, name, url, classid from subject where adopt = 1")
    List<BrifSubject> selectBrif();

    //添加
    @Update("insert into subject values(#{id}, #{classid}, #{uid}, #{name}, " +
            "#{date}, #{description}, #{url}, #{star}, #{click}, #{adopt})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    Integer addSubject(Subject subject);

    //点击量
    @Update("update subject set click = #{click} where id = #{id}")
    int click(Integer id, Integer click);

    //新上传
    @Select("select * from subject where adopt = 0")
    List<Subject> getNewSubject();

    @Update("update subject set adopt = 1 where id = #{id}")
    Integer allowSubject(Integer id);

    @Select("select * from subject where id = #{id}")
    Subject adminSubject(Integer id);

    @Update("update subject set adopt = -1 where id = #{id}")
    Integer refuseSubject(Integer id);

    @Update("update subject set adopt = -2 where id = #{id}")
    Integer deleteSubject(Integer id);

    @Select("select * from subject where uid = #{id}")
    List<Subject> personalSubject(Integer id);
}